package com.mk.settlement.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mk.settlement.common.Page;
import com.mk.settlement.enums.SettlementStatusEnums;
import com.mk.settlement.mappers.SettlementResultMapper;
import com.mk.settlement.model.SettlementResult;
import com.mk.settlement.service.SettlementResultService;

/**
 * 结算结果展示service实现类
 * @author futao
 *
 */
@Service
public class SettlementResultServiceImpl implements SettlementResultService {
	
	@Autowired
	private SettlementResultMapper settlementResultMapper;
	
	//查询要现实的数据
	public Page findData(SettlementResult sresult,Page page ){
		List<SettlementResult> result=settlementResultMapper.findStatisticaResultList(sresult.getSettlementTargetName(),
				sresult.getSettlementStatus(),
				sresult.getSettlementCategory(),
				sresult.getSaleType(),
				page.getStart(), 
				page.getPageSize(), 
				page.getCurrentPage(),
				page.getOrderby());
		page.setResult(result);
		int count=settlementResultMapper.selectStatisticaResultCount(sresult.getSettlementTargetName(),
				sresult.getSettlementStatus(),
				sresult.getSettlementCategory(),
				sresult.getSaleType() );
	    page.setTotalRecord( count );
	    page.setTotalPage(page.getTotalPage());
		return page;
	}
	
	@Override   //导出用的查询
	public List<String[]> findExportData(int titileSize,SettlementResult sresult,Page page) {
		List<String[]> list=new ArrayList<>();
		List<SettlementResult>  result = settlementResultMapper.findStatisticaResultList(
				sresult.getSettlementTargetName(),
				sresult.getSettlementStatus(),
				sresult.getSettlementCategory(),
				sresult.getSaleType(), 
				page.getStart(), 
				page.getPageSize(), 
				page.getCurrentPage(),
				page.getOrderby());
		String str[]=null;
		for (SettlementResult sr:result) {
			str=new String[titileSize];
			str[0]=sr.getSettlementTargetName();
			str[1]=sr.getStrFeeType();
			str[2]=sr.getSettlementTotalSum()+"";
			str[3]=sr.getSettlementSaleSum()+"";
			str[4]=sr.getStrSettlementStatus();
			str[5]=sr.getStrSettlementType();
			str[6]=sr.getStrSettlementCategory();				
			str[7]=sr.getStrSaleType();
			str[8]=sr.getStrSettlementBeginTime();
			str[9]=sr.getStrSettlementEndTime();
			str[10]=sr.getStrCreateTime();
			
			list.add(str);
		}
		return  list;
	}

	/**
	 * 更新数据
	 * @param settlementResult
	 * 参数：SettlementResult数据
	 * @return int
	 * 返回值
	 */
    @Override
    public int updateByPrimaryKeySelective(SettlementResult settlementResult) {
        return settlementResultMapper.updateByPrimaryKeySelective(settlementResult);
    }

    /**
     * 删除数据
     * @param id
     * 参数：主键id
     * @return int
     * 返回值
     */
    @Override
    public int deleteByPrimaryKey(Long id) {
        return settlementResultMapper.deleteByPrimaryKey(id);
    }
    
    @Override
	public int settlements(String ids){
    	return settlementResultMapper.settlements(ids.split(","),
    			SettlementStatusEnums.DONE_SETTLEMENT.getIndex());
	}
	

}